import pytest
from PO.utils import DriverUtil, get_alert_msg


class TestLogin:

    def setup_class(self):
        self.driver = DriverUtil.get_driver()

    @staticmethod
    def teardown_class():
        DriverUtil.quit_driver()

    def setup(self):
        self.driver.get("http://127.0.0.1")
        self.driver.find_element("link text", "登录").click()

    def teardown(self):
        pass

    def test_account_no_exist(self):
        self.driver.find_element("id", "username").send_keys("15021241001")
        self.driver.find_element("id", "password").send_keys("123456")
        self.driver.find_element("id", "verify_code").send_keys("8888")
        self.driver.find_element("class name", "login_bnt").click()
        # msg = self.driver.find_element("class name", "layui-layer-content").text
        msg = get_alert_msg()
        print(msg)

    def test_wrong_password(self):
        self.driver.find_element("id", "username").send_keys("15021241000")
        self.driver.find_element("id", "password").send_keys("12345")
        self.driver.find_element("id", "verify_code").send_keys("8888")
        self.driver.find_element("class name", "login_bnt").click()
        # msg = self.driver.find_element("class name", "layui-layer-content").text
        # assert msg == "账户名不存在或密码不匹配，请重新输入！"
        msg = get_alert_msg()
        print(msg)


if __name__ == '__main__':
    pytest.main(["-sv", "tpshop_login_2.py"])
